﻿#include <iostream>

using namespace std;
class vector3 {
private:
	int x;
	int y;
	int z;
protected:
public:
	/// <summary>
	/// 构造函数
	/// </summary>
	/// <param name="x">x轴</param>
	/// <param name="y">y轴</param>
	/// <param name="z">z轴</param>
	vector3(int x, int y, int z) {
		this->x = x;
		this->y = y;
		this->z = z;
	}
	/// <summary>
	/// 构造函数
	/// </summary>
	/// <param name="xyz">数组</param>
	vector3(int* xyz) {
		this->x = xyz[0];
		this->y = xyz[1];
		this->z = xyz[2];
	}
	/// <summary>
	/// 拷贝构造函数，拷贝构造函数在一个对象作为参数传递给函数的时候调用
	/// </summary>
	/// <param name="v"></param>
	vector3(const vector3& v) {
		this->x = v.x;
		this->y = v.y;
		this->z = v.z;
	}
	/// <summary>
	/// 析构函数
	/// </summary>
	~vector3() {};
	//重写+号
	vector3 operator+(vector3 v) {
		return vector3(v.x + this->x, v.y + this->y, v.z + this->z);
	}
	//重写-号
	vector3 operator-(vector3 v) {
		return vector3(v.x - this->x, v.y - this->y, v.z - this->z);
	}
	//重写[]下标号
	int operator[](int i) {
		if (i == 0) return this->x;
		if (i == 1) return this->y;
		if (i == 2) return this->z;
	}
	//重写标准输出符<< 使用友元函数
	friend ostream& operator<<(ostream& os, const vector3& v);
};
//
ostream& operator<<(ostream& os, const vector3& v) {
	os << "{"
		<< "x : " << v.x << ", "
		<< "y : " << v.y << ", "
		<< "z : " << v.z
		<< "}";
	return os;
}


class line {
private:
	int length;
public:
	//类静态变量
	static int count;
	line(int length);
	/// <summary>
	/// 拷贝构造函数 在作为函数参数时会调用该函数
	/// </summary>
	/// <param name="l"></param>
	line(const line& l);
	line operator+(const line l);
	line operator-(const line l);
	bool operator<(const line l);
	bool operator>(const line l);
	bool operator==(const line l);
	int getLength() const;
	friend ostream& operator<<(ostream& os, const line& l);
};
int line::count = 0;//初始化类静态变量
line::line(int length) {
	this->length = length;
}
line::line(const line& l) {
	this->length = l.length;
}
int line::getLength() const {
	return this->length;
}
line line::operator+(const line l) {
	line rtn(this->length + l.length);
	return rtn;
}
line line::operator-(const line l) {
	line rtn(this->length - l.length);
	return rtn;
}
bool line::operator<(const line l) {
	return this->length < l.length;
}
bool line::operator>(const line l) {
	return this->length > l.length;
}
bool line::operator==(const line l) {
	return this->length == l.length;
}
ostream& operator<<(ostream& os, const line& l) {
	os << l.length;
	return os;
}

//父类 图形类
class shape {
protected:
	double width;
	double height;

public:
	void setWidth(double width) {
		this->width = width;
	}
	void setHeight(double height) {
		this->height = height;
	}
};

class shape2 {
protected:
	double width;
	double height;
public:
	void setWidth(double width) {
		this->width = width;
	}
	void setHeight(double height) {
		this->height = height;
	}
};

class base_class {
public:
	base_class(int a, int b) {
	}
};

class child_class : public base_class{
public:
	child_class(int a, int b) : base_class(a, b) {
	}
};

class base_shape {
protected:
	int width, height;
public:
	base_shape(int width, int height) {
		this->width = width;
		this->height = height;
	}
	//纯虚函数 必须被实现的函数
	virtual int area() = 0;
};

class rectangle : public base_shape {
public:
	rectangle(int width, int height) : base_shape(width, height) {}
	int area() {
		return this->width * this->height;
	}
};

class triangle : public base_shape {
public:
	triangle(int width, int height) : base_shape(width, height) {}
	int area() {
		return this->height * this->width / 2;
	}
};





/// <summary>
/// 面向对象
/// </summary>
/// <param name=""></param>
/// <returns></returns>
void printLine(line line);
inline line max(line a, line b);
void printShapeArea(base_shape* shape);
int mainOop(void) {
	/*vector3 nv = {1,2,3};
	vector3 nvc = { 1,2,3 };
	vector3 ns = nv + nvc;
	cout << ns << endl;*/
	//line ll = 12;
	////printLine(ll);
	//
	//line la = 1;
	//line lb = 2;
	//line lc = max(la, lb);
	////cout << lc << endl;
	//
	////类型指针
	//line* lp = nullptr;
	////lp = &ll;
	////分配内存使用new
	//lp = new line(12);

	//cout << *lp << endl;
	//多态
	base_shape* rec = new rectangle(4, 4);
	base_shape* tri = new triangle(4, 4);
	printShapeArea(rec);
	printShapeArea(tri);
	return 1;
}

void printShapeArea(base_shape* shape) {
	cout << shape->area() << endl;
}

void printLine(line line) {
	cout << line << endl;
}
line max(line a, line b) {
	return a > b ? a : b;
}
